package manager;

import entity.Mark;
import entity.Student;
import entity.Subject;
import iface.IManager;
import java.util.ArrayList;

/**
 *
 * @author Noi
 */
public class MarkManager implements IManager<Mark> {

    private ArrayList<Mark> markList;

    public MarkManager() {
        this.markList = new ArrayList<Mark>();
    }

    @Override
    public boolean add(Mark mark) {
        return this.markList.add(mark);
    }

    @Override
    public boolean remove(Mark mark) {
        return this.markList.remove(mark);
    }

    @Override
    public Mark replace(int index, Mark mark) {
        return this.markList.set(index, mark);
    }

    @Override
    public int size() {
        return this.markList.size();
    }

    @Override
    public Mark get(int index) {
        return this.markList.get(index);
    }

    public ArrayList<Mark> getByStudentId(String studentID) {
        ArrayList<Mark> alMark = new ArrayList<Mark>();
        for (int i = 0; i < this.markList.size(); i++) {
            if (this.markList.get(i).getStudentID().equals(studentID)) {
                alMark.add(this.markList.get(i));
            }
        }
        return alMark;
    }

    public Mark getMark(int subjectID, Student student) {
        for (Mark mark : this.markList) {
            if (mark.getStudentID().equals(student.getStudentID()) && subjectID == mark.getSubjectID()) {
                return mark;
            }
        }
        return null;
    }
    
    public ArrayList<Mark> getBySubjectAndStudentID(String studentID, ArrayList<Subject> alSubject) {
        ArrayList<Mark> alMark = new ArrayList<Mark>();
        for (Mark mark : this.markList) {
            for (Subject subject : alSubject) {
                if (mark.getStudentID().equals(studentID) && mark.getSubjectID() == subject.getSubjectID()) {
                    alMark.add(mark);
                    break;
                }
            }
        }
        return alMark;
    }

    @Override
    public Mark getById(int id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Mark getByName(String name) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void setVisible(Mark obj, boolean value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Mark contains(Mark obj) {
        for (Mark mark : this.markList) {
            if (mark.getStudentID().equals(obj.getStudentID()) && mark.getSubjectID() == obj.getSubjectID()) {
                return obj;
            }
        }
        return null;
    }
}
